package ctrlzone;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import dao.MyDAO;

import javax.swing.JLabel;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.awt.Color;

public class ViewCtrlZone extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {

		ViewCtrlZone frame = new ViewCtrlZone();
	}

	/**
	 * Create the frame.
	 */
	public ViewCtrlZone() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 484, 451);
		contentPane = new JPanel();
		setVisible(true);
		
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("控制区详细信息");
		label.setFont(new Font("华文宋体", Font.BOLD, 17));
		label.setBounds(175, 10, 149, 21);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("编号：");
		label_1.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_1.setBounds(145, 64, 45, 15);
		contentPane.add(label_1);
		
		//控制区编号显示
		JLabel label_Id = new JLabel();
		label_Id.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Id.setBounds(252, 64, 141, 15);
		contentPane.add(label_Id);
		
		JLabel label_2 = new JLabel("名称：");
		label_2.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_2.setBounds(145, 99, 45, 15);
		contentPane.add(label_2);
		
		//控制区名称显示
		JLabel label_Name = new JLabel();
		label_Name.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Name.setBounds(252, 99, 145, 15);
		contentPane.add(label_Name);
		
		JLabel label_3 = new JLabel("总面积：");
		label_3.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_3.setBounds(130, 135, 60, 15);
		contentPane.add(label_3);
		
		//控制区总面积显示
		JLabel label_Area = new JLabel();
		label_Area.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Area.setBounds(252, 135, 141, 15);
		contentPane.add(label_Area);
		
		JLabel label_4 = new JLabel("运行状态：");
		label_4.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_4.setBounds(117, 176, 90, 15);
		contentPane.add(label_4);
		
		//运行状态显示
		JLabel label_Status = new JLabel();
		label_Status.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Status.setBounds(252, 176, 141, 15);
		contentPane.add(label_Status);
		
		JLabel lblNewLabel_4 = new JLabel("功能类型：");
		lblNewLabel_4.setFont(new Font("华文宋体", Font.PLAIN, 15));
		lblNewLabel_4.setBounds(115, 216, 75, 15);
		contentPane.add(lblNewLabel_4);
		
		//功能类型显示
		JLabel label_Func = new JLabel();
		label_Func.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Func.setBounds(252, 216, 141, 15);
		contentPane.add(label_Func);
		
		JLabel label_5 = new JLabel("作物种类：");
		label_5.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_5.setBounds(115, 257, 75, 15);
		contentPane.add(label_5);
		
		//作物种类显示
		JLabel label_Crop = new JLabel();
		label_Crop.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Crop.setBounds(251, 257, 142, 15);
		contentPane.add(label_Crop);
		
		JLabel label_6 = new JLabel("方法类型：");
		label_6.setFont(new Font("华文宋体", Font.PLAIN, 15));
		label_6.setBounds(115, 293, 75, 15);
		contentPane.add(label_6);
		
		//方法类型显示
		JLabel label_Method = new JLabel();
		label_Method.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Method.setBounds(252, 293, 141, 15);
		contentPane.add(label_Method);
		
		JLabel lblNewLabel_8 = new JLabel("地理位置：");
		lblNewLabel_8.setFont(new Font("华文宋体", Font.PLAIN, 15));
		lblNewLabel_8.setBounds(115, 327, 75, 15);
		contentPane.add(lblNewLabel_8);
		
		//地理位置显示
		JLabel label_Location = new JLabel();
		label_Location.setFont(new Font("华文宋体", Font.BOLD, 15));
		label_Location.setBounds(252, 327, 141, 15);
		contentPane.add(label_Location);
		
		Connection conn = null;
		Statement stmt = null;
		ResultSet rSet = null;
		
		String sql = "select * from ctrlzone_para;";
		
		try {
			conn = MyDAO.getConnection();
			stmt = conn.createStatement();
			rSet = stmt.executeQuery(sql);
			while (rSet.next()) {
				label_Id.setText(rSet.getString(1).toString());
				label_Name.setText(rSet.getString(2).toString());
				label_Area.setText(rSet.getString(4).toString());
				label_Status.setText(rSet.getString(5).toString());
				label_Func.setText(rSet.getString(6).toString());
				label_Crop.setText(rSet.getString(8).toString());
				label_Method.setText(rSet.getString(7).toString());
				label_Location.setText(rSet.getString(3).toString());
				setTitle("当前控制区："+rSet.getLong(2));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setLocationRelativeTo(null);
	}
}
